package edu.serg.mbar.algorithms.functions;

import java.util.Vector;

import org.apache.log4j.Logger;

import edu.serg.mbar.ucon.interfaces.IFunction;

/**
 * This class is representative of the function for subtracting some values from another values
 * 
 * @author Sanaullah
 *
 */

public class Subtract implements IFunction {
	static Logger log = Logger.getLogger(Subtract.class);

	@Override
	/**
	 * This function evaluates the difference between some values
	 * 
	 * @param
	 * The vector of objects whose difference is to be calculated, all of the items in the vector are subtracted
	 * from the first element in the vector
	 * 
	 */
	public Object evaluate(Vector<Object> param) {
		log.debug("*Executing subtract Function");
		double result=0;
		
		Double firstValue = (Double) param.elementAt(0);
		log.debug("The first element in the vector is " + firstValue);
		
		for (int i =1; i < param.size();i++){
			log.debug("Subtracting " + (Double) param.elementAt(i) + " from " + firstValue);
			firstValue =firstValue - (Double) param.elementAt(i);
			log.debug("=" + firstValue);
		}
		result =firstValue.doubleValue();
		log.debug("*Returning the final value of the Subtraction operation which is " + result);		
		return result;
	}

}
